package com.zhijian.medical.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhijian.medical.dao.local.ExperimentProcessSampleLogMapper;
import com.zhijian.medical.entity.po.ExperimentProcessSampleLog;
import com.zhijian.medical.service.ExperimentProcessSampleLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author li xiao dong
 * @since 2022-08-26
 */
@Service
public class ExperimentProcessSampleLogServiceImpl extends ServiceImpl<ExperimentProcessSampleLogMapper, ExperimentProcessSampleLog> implements ExperimentProcessSampleLogService {
    @Autowired
    private ExperimentProcessSampleLogMapper sampleLogMapper;

    @Override
    public List<ExperimentProcessSampleLog> list(Long sampleId) {
        QueryWrapper<ExperimentProcessSampleLog> experimentProcessSampleLogQueryWrapper = new QueryWrapper<>();
        experimentProcessSampleLogQueryWrapper.eq("sample_id", sampleId);
        return sampleLogMapper.selectList(experimentProcessSampleLogQueryWrapper);
    }

    @Override
    public Boolean create(ExperimentProcessSampleLog sampleLog) {
        return sampleLogMapper.insert(sampleLog) > 0;
    }

    @Override
    public boolean saveBatch(List<ExperimentProcessSampleLog> entities) {
        return CollectionUtil.isNotEmpty(entities) && sampleLogMapper.insertBatch(entities) > 0;
    }

    @Override
    public Boolean delete(Long sampleId) {
        QueryWrapper<ExperimentProcessSampleLog> experimentProcessSampleLogQueryWrapper = new QueryWrapper<>();
        experimentProcessSampleLogQueryWrapper.eq("sample_id", sampleId);
        return sampleLogMapper.delete(experimentProcessSampleLogQueryWrapper) > 0;
    }
}
